﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Web.PuntoDeVenta.Code
{
    public static class HttpHelper
    {
        public const string cookiePtoVtaName = "ptoDeVenta";
        public const string cookieCompany = "cookieCompany";       

        public static string GetCookieValue(string cookieName, HttpRequest request)
        {
            string cookieValue = null;
            if (request.Cookies[cookieName] != null)
            {
                return request.Cookies[cookieName].Value;
            }

            return cookieValue;
        }

        public static List<string> GetCookieValues(string cookieName, HttpRequest request)
        {
            List<string> values = new List<string>();
            
            if (request.Cookies[cookieName] != null)
            {
                for (int i = 0; i < request.Cookies[cookieName].Values.Count; i++ )
                {
                    values.Add(request.Cookies[cookieName].Values[i]);
                }                
            }

            return values;
        }

        public static void SetCookieValue(string cookieName, HttpResponse response, string value)
        {
            response.Cookies[cookieName].Value = value;
            response.Cookies[cookieName].Expires = DateTime.Now.AddYears(2);
        }

        public static void SetCookieValues(string cookieName, HttpResponse response, params string[] values)
        {
            int i = 0;
            foreach (string s in values)
            {
                response.Cookies[cookieName][cookieName + "_" + i.ToString()] = s;
                i++;
            }

            response.Cookies[cookieName].Expires = DateTime.Now.AddYears(2);
        }
    }
}